package com.open.rbac.service.sys.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.open.rbac.model.entity.sys.RoleUserRel;


public interface RoleUserRelRepository extends JpaRepository<RoleUserRel, String> {

    /**
     * 按角色Id物理删除'角色与用户关系'
     */
    @Modifying
    @Transactional
    @Query("DELETE FROM role_user_rel rel WHERE rel.roleId = ?1")
    void deleteReallyByRoleId(String roleId);

    /**
     * 按用户Id物理删除'角色与用户关系'
     */
    @Modifying
    @Transactional
    @Query("DELETE FROM role_user_rel rel WHERE rel.userId = ?1")
    void deleteReallyByUserId(String userId);


    @Query("SELECT t1 FROM role_user_rel t1 WHERE t1.userId IN (?1)")
    List<RoleUserRel> findByUserIds(List<String> userIds);
}
